//
//  Database.m
//  谈诗说词
//
//  Created by dllo on 15/6/15.
//  Copyright (c) 2015年 lanou3g.com蓝鸥科技. All rights reserved.
//

#import "Database.h"
#import "DB.h"
@implementation Database
+ (void)commitaql:(NSString *)str
{
    sqlite3 *db = [DB openDB];
    //执行sql语句
    int result = sqlite3_exec(db, [str UTF8String], nil, nil, nil);
    //判断是否执行成功
    if (result == SQLITE_OK) {
        NSLog(@"成功");
    } else {
        NSLog(@"失败");
    }
    
}


+ (NSArray *)selectAll
{
    NSString *str = @"select name from name";
    sqlite3 *db = [DB openDB];
    sqlite3_stmt *stmt = nil;
    int result = sqlite3_prepare_v2(db, [str UTF8String], -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
        NSLog(@"查询成功");
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            const unsigned char *name = sqlite3_column_text(stmt, 0);
            
            
            NSString *namea = [NSString stringWithUTF8String:(const char *)name];
            
            
            
            [array addObject:namea];
        }
    }else{
        NSLog(@"查询失败");
    }
    return array;
    
}

@end
